﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Net;

namespace WpfApplication
{
    /// <summary>
    /// Interaction logic for Login.xaml
    /// </summary>
    public partial class LoginWindow : Window
    {
        MainWindow mainWindow;
        SecureCalibration secureCal;

        public LoginWindow(MainWindow mW)
        {
            InitializeComponent();
            mainWindow = mW;
            secureCal = new SecureCalibration();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (secureCal.checkLogin(textBox1.Text, textBox2.Text))
                {
                    // user validated!
                    mainWindow.Reset();
                    mainWindow.modeLabel.Content = "Mode: Calibration";
                    mainWindow.button4.Content = "EXIT CAL";
                    mainWindow.button4.Foreground = Brushes.Red;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Username or password not valid",
                          "Client Authentication Services", MessageBoxButton.OK,
                          MessageBoxImage.Warning);
                }
            }
            catch (WebException ex)
            {
                MessageBox.Show(ex.Message, "Client Application Services",
                      MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}
